<script type="text/javascript">
function cart_set(goods_id,quantity)
{
    showPageLoadingMsg('处理中...');
    $.getJSON('/cart/set?goods_id=' + goods_id + '&quantity=' + quantity, function(result){
        $(".ui-loader").remove();
        if(result.status == 1){
            $('#totalPrice').html( result.amount);
            
        }else{
           floatNotify.simple(result.msg);
          
           $('#pamount_'+goods_id).val(parseInt($('#pamount_'+goods_id).val())-1);
        }
    });
}
var setAmount={
    min:1,
    max:999,
    reg:function(x){
        return new RegExp("^[1-9]\\d*$").test(x);
    },
    amount:function(obj,mode){
        var x=$(obj).val();
        if (this.reg(x)){
            if (mode){
                x++;
            }else{
                x--;
            }
        }else{
            floatNotify.simple("请输入正确的数量！");
            $(obj).val(1);

        }
        return x;
    },
    reduce:function(obj){
        var x=this.amount(obj,false);
        if (x>=this.min){
            cart_set($(obj).attr('rel'),x);
            $(obj).val(x);
        }else{
            floatNotify.simple("商品数量最少为"+this.min);
            $(obj).val(1);
        }

    },
    add:function(obj){
        var x=this.amount(obj,true);
        if (x<=this.max){
            
            $(obj).val(x);
            cart_set($(obj).attr('rel'),x);
        }else{
            floatNotify.simple("商品数量最多为"+this.max);
            $(obj).val(this.max);
        }
    },
    modify:function(obj){
        var x=$(obj).val();
        if (x<this.min||x>this.max||!this.reg(x)){
            floatNotify.simple("请输入正确的数量！");
            $(obj).val(1);
        }else{
            cart_set($(obj).attr('rel'),x);
        }
    }
}
</script>